<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta name="description" content="">
    <meta http-equiv="x-dns-prefetch-control" content="on">

    <title>车辆信息</title>
    <link href="../../css/css.css" rel="stylesheet" type="text/css">
    <script src="../../js/jquery-v1.11.2.min.js"></script>
    <script src="../../js/driver.js"></script>
    <script src="../../js/common.js"></script>
    <script src="../../js/ajaxfileupload.js"></script>
    <style>
        .set_top {
            position: absolute;
            left: 30%;
            opacity: 0;
            top: 30%;
        }
    </style>
</head>
<body>
<form id="vehicleForm">
    <section class="itemgroup p15 mt10">
        <div class="inputarea">
            <label class="inputname">车辆信息</label>
            <label class="inputform" id="vehicleTypeList">
                <i class="iconfont wipe">&#xe6db;</i>
                <label class="gray">请选择车辆信息</label>
            </label>
        </div>
        <div class="inputarea">
            <label class="inputname">车牌号</label>
            <label class="inputform">
                <i class="iconfont wipe">&#xe614;</i>
                <input class="formstyle w100" type="text" placeholder="请输入车牌号" id="vehicleNum" name="vehicleNum"/>
            </label>
        </div>
    </section>
    <section class="subtitle mt10 p15"><font onclick="delegate.clickOnAndroid();">请上传车辆外观照片</font></section>
    <section class="itemgroup p15">
        <div class="photoitem">
            <div class="add_photo3 mr2p" style="position: relative;" onclick="uploadImg('idCardImage');">
                <div class="delphoto" style="top:-40px" hidden id="idCardImageDelDiv"
                     onclick="deleteImage('idCardImage')">
                    <img src="../../img/del_btn.png" width="100%" height="100%"/>
                </div>
                <div id="idCardImageOtherReal">
                    <i class="iconfont">&#xe60d;</i>
                </div>
                <img src="#" width="100%" height="100%" hidden id="idCardImageReal"/>
                <input type="hidden" name="billAttachId" id="idCardImagebillAttachId">
                <label class="photo_title">身份证</label>
            </div>
            <div class="add_photo3 mr2p" style="position: relative;" onclick="uploadImg('driverImage');">
                <div class="delphoto" style="top:-40px" hidden id="driverImageDelDiv"
                     onclick="deleteImage('driverImage')">
                    <img src="../../img/del_btn.png" width="100%" height="100%"/>
                </div>

                <div id="driverImageOtherReal">
                    <i class="iconfont">&#xe60d;</i>
                </div>
                <img src="#" width="100%" height="100%" hidden id="driverImageReal"/>
                <input type="hidden" name="billAttachId" id="driverImagebillAttachId">
                <label class="photo_title">司机照片</label>
            </div>
            <div class="add_photo3" style="position: relative;" onclick="uploadImg('vehicleImage');">
                <div class="delphoto" style="top:-40px" hidden id="vehicleImageDelDiv"
                     onclick="deleteImage('vehicleImage')">
                    <img src="../../img/del_btn.png" width="100%" height="100%"/>
                </div>
                <div id="vehicleImageOtherReal">
                    <i class="iconfont">&#xe60d;</i>
                </div>
                <img src="#" width="100%" height="100%" hidden id="vehicleImageReal"/>
                <input type="hidden" name="billAttachId" id="vehicleImagebillAttachId">
                <label class="photo_title">车辆照片</label>
            </div>
            <div class="add_photo3 mr2p" style="position: relative;" onclick="uploadImg('driverCardImage');">
                <div class="delphoto" style="top:-40px" hidden id="driverCardImageDelDiv"
                     onclick="deleteImage('driverCardImage')">
                    <img src="../../img/del_btn.png" width="100%" height="100%"/>
                </div>
                <div id="driverCardImageOtherReal">
                    <i class="iconfont">&#xe60d;</i>
                </div>
                <img src="#" width="100%" height="100%" hidden id="driverCardImageReal"/>
                <input type="hidden" name="billAttachId" id="driverCardImagebillAttachId">
                <label class="photo_title">驾驶证</label>
            </div>
            <div class="add_photo3 mr2p" style="position: relative;" onclick="uploadImg('drivingLicenseImage');">
                <div class="delphoto" style="top:-40px" hidden id="drivingLicenseImageDelDiv"
                     onclick="deleteImage('drivingLicenseImage')">
                    <img src="../../img/del_btn.png" width="100%" height="100%"/>
                </div>
                <div id="drivingLicenseImageOtherReal">
                    <i class="iconfont">&#xe60d;</i>
                </div>
                <img src="#" width="100%" height="100%" hidden id="drivingLicenseImageReal"/>
                <input type="hidden" name="billAttachId" id="drivingLicenseImagebillAttachId">
                <label class="photo_title">行驶证</label>
            </div>
            <div class="add_photo3" style="position: relative;" onclick="uploadImg('operationCertificateImage');">
                <div class="delphoto" style="top:-40px" hidden id="operationCertificateImageDelDiv"
                     onclick="deleteImage('operationCertificateImage')">
                    <img src="../../img/del_btn.png" width="100%" height="100%"/>
                </div>
                <div id="operationCertificateImageOtherReal">
                    <i class="iconfont">&#xe60d;</i>
                </div>
                <img src="#" width="100%" height="100%" hidden id="operationCertificateImageReal"/>
                <input type="hidden" name="billAttachId" id="operationCertificateImagebillAttachId">
                <label class="photo_title">运营证</label>
            </div>
        </div>
    </section>
    <section class="signbtnarea mt44">
        <input type="hidden" name="driverUserId" id="driverUserId">
        <input type="hidden" name="pictureId" id="pictureId">
        <button type="button" class="btn bottomonebtn" onclick="regVehicleSave();">提交</button>
    </section>
</form>
<script type="text/javascript">
    $(document).ready(function () {
        var driverUserId = GetArgsFromHref("driverUserId");
        var url = _global.serverHost + "/driver/regVehicle.htm";
        var data = {driverUserId: driverUserId};
        _callAjaxRequest(url, data, startBidBack);

        function startBidBack(data) {
            var vehicleTypeList = '<i class="iconfont wipe">&#xe6db;</i>' +
                    '<select id="vehicleTypeS" name="vehicleTypeS" class="gray">' +
                    '<option value="">请选择车辆类型</option>';
            for (var i = 0; i < data.vehicleTypeList.length; i++) {
                vehicleTypeList = vehicleTypeList + '<option value="' + data.vehicleTypeList[i].codeValueS + '">' + data.vehicleTypeList[i].cvName + '-' + data.vehicleTypeList[i].cvNameS + '</option>';
            }
            vehicleTypeList = vehicleTypeList + "</select>";
            $("#vehicleTypeList").html(vehicleTypeList);
            $("#driverUserId").val(data.driverUserId);
            $("#pictureId").val(data.pictureId);
        }

    });
    function regVehicleSave() {
        var url = _global.serverHost + "/driver/regVehicleSave.htm";
        var data = $("#vehicleForm").serialize();
        _callAjaxRequest(url, data, regVehicleSaveBack);
    }

    function regVehicleSaveBack(data) {
        if (data.code == "1") {
            window.location.href = "../login.html";
        } else {
            alert(data.message);
        }
    }

    function deleteImage(fileElementId) {
        $.ajax({
            type: "POST",
            url: _global.serverHost + "/driver/deleteImage.htm",
            data: {billAttachId: $("#" + fileElementId + "billAttachId").val()},
            contentType: "application/x-www-form-urlencoded;charset=UTF-8",
            success: function (data) {
                if (data.code == "1") {
                    $("#" + fileElementId + "Real").attr("src", "#");
                    $("#" + fileElementId + "OtherReal").show();
                    $("#" + fileElementId + "Real").hide();
                    $("#" + fileElementId + "DelDiv").hide();
//                    $("#pictureId").val("");
                    $("#" + fileElementId + "billAttachId").val("");
                } else {
                    alert(data.message);
                }
            }
        });
    }
    
    function uploadImg(fileElementId) {
    	
    	var tempGuid=guid();
    	fileElementIdFull = fileElementId;
    	var urlpara = "guid="+tempGuid+"&billId=" + $("#driverUserId").val() + "&pictureId=" + $("#pictureId").val() + "&fileElementId=" + fileElementId + "&driverUuid=" + getCookie("driverUuid");
    	delegate.clickOnAndroid(urlpara,fileElementId);
    }
    var fileElementIdFull;
    function uploadHead(fileElementId) {
    	
    	var tempGuid=guid();
    	
    	var urlpara = "guid="+tempGuid+"&billId=" + $("#driverUserId").val() + "&pictureId=" + $("#pictureId").val() + "&fileElementId=" + fileElementId + "&driverUuid=" + getCookie("driverUuid");
    	delegate.clickOnAndroid(urlpara,fileElementId);
//        $.ajaxFileUpload({
//            url: _global.serverHost + "/driver/uploadVehicle.htm?guid="+tempGuid+"&billId=" + $("#driverUserId").val() + "&pictureId=" + $("#pictureId").val() + "&fileElementId=" + fileElementId + "&driverUuid=" + getCookie("driverUuid"),
//            secureuri: false,
//            fileElementId: fileElementId,//文件选择框的id属性
//            dataType: 'json',   //json
//            success: function (data) {
//            	$.ajax({
//                    type: "POST",
//                    url: _global.serverHost + "/driver/getImageByGuid.htm",
//                    data: {guid: tempGuid},
//                    contentType: "application/x-www-form-urlencoded;charset=UTF-8",
//                    success: function (data) {
//                    	//根据图片的GUID获取信息
//                        console.log("===="+JSON.stringify(data));
//                        $("#" + fileElementId + "Real").attr("src", data.fileUrl);
//                        $("#" + fileElementId + "OtherReal").hide();
//                        $("#" + fileElementId + "Real").show();
//                        $("#" + fileElementId + "DelDiv").show();
//                        $("#" + fileElementId + "billAttachId").val(data.billAttachId);
//                        $("#pictureId").val(data.pictureId);
//                    }
//                });
//            }, error: function (XMLHttpRequest, textStatus, errorThrown) {
//                alert('上传失败！');
//            }
//        });
    }
    
    window.submitDone = function(data){   	
    	$("#" + fileElementIdFull + "Real").attr("src", data.fileUrl);
      $("#" + fileElementIdFull + "OtherReal").hide();
      $("#" + fileElementIdFull + "Real").show();
      $("#" + fileElementIdFull + "DelDiv").show();
			$("#pictureId").val(data.pictureId);
		};
</script>
</body>
</html>